<?php 
session_start();
$_SESSION['debug'] = false;
if($_SESSION['debug']){
	$_SESSION['userdata']['username'] = "publisher2";	
	$_SESSION['rule'] = "PUBLISHER";						
	$_SESSION['auth'] = true;
}				
if ($_SESSION['auth'] != true || $_SESSION['rule'] != "PUBLISHER") {
	$currUrl = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
	header("location:$currUrl/login.html");
	echo "please login.";
	echo "<br>redirecting...";
	exit();
}
include("includes/publisher_lib.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Publisher</title>
<link href="itelement.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="script/jquery.js"></script>
<script language="javascript">
var timeout = 10000;	//ms
var NO_UPDATE = <? echo "'$NO_UPDATE';"; ?>	//"NO_UPDATE";
var MOZILLA = (document.getElementById?true:false);
var IE = (document.all?true:false); 

$(document).ready (
	function () {
		updateSuspend();
		
	}
);

function updateSuspend(){
	var init = $('#suspend').text().length == 0?'&init=init':'';
	$.get("publisher_operation.php?action=update_suspend"+init,
		function(data){
			//alert(data);
			if(data != NO_UPDATE)
				$('#suspend').html(data);
		} );
	window.setTimeout('updateSuspend()',timeout);
}

function showAddItem(){
	var id = $("#addch").val();
	$("#main-right-box").attr('src', "provider_add_item.php?id="+id);	
}

var is_collapsed = false;

function ToggleCollapse()
{
    if (is_collapsed) { 
        document.getElementById("nav").style.display = '';
        document.getElementById("collapse").style.display = "";
        document.getElementById("expand").style.display = 'none';
        is_collapsed = false;
    } else {
        document.getElementById("nav").style.display = 'none';
        document.getElementById("collapse").style.display = "none";
        document.getElementById("expand").style.display = '';
        is_collapsed = true;
    }
}
</script>
</head>
<body>
<div class="itelement" id="header">IT Element </div>
<div class="main">
  <table id="main-table">
    <tr>
      <td width="1"><div class="nav" id="nav">
	  <div class="nav-item">
          <table width="100%">
            <tr>
              <td><div class="nav-header">Create new item to channel</div></td>
              </tr>
            <tr>
              <td>
			  	<table width="100%">
				<tr><td>
			  	<select id="addch" style="width:200px">
				  <?php
				  $avch = getAvailableChannel($_SESSION['userdata']['username']);
				  foreach($avch as $c)
				  {
				  echo "<option value=\"".$c['id']."\">".$c['title']."</option>";
				  }
				  ?>
                 </select>
				 </td>
				 <td style="text-align:right"><input type="button" value="add" onClick="showAddItem()"></td>
				 </tr></table>
              </td>
              </tr>
          </table>
        </div>
        <div class="nav-item">
          <table width="100%">
            <tr>
              <td><div class="nav-header">Requested for Approve</div></td>
            </tr>
            <tr>
              <td><div id="suspend" class="nav-container" style="height:100%"></div></td>
            </tr>
          </table>
        </div>
		
        </div></td>
      <td id="expand" width="3" style="background-color:#E6E9EE;vertical-align:middle;display:none" onMouseOver="this.style.backgroundColor='#CFCED2'" onMouseOut="this.style.backgroundColor='#E6E9EE'" onClick="ToggleCollapse()" title="Expand pane"><img src="img/expand.gif" /></td>
      <td id="collapse" height="100%" width="3" style="background-color:#E6E9EE;vertical-align:middle" onMouseOver="this.style.backgroundColor='#CFCED2'" onMouseOut="this.style.backgroundColor='#E6E9EE'" onClick="ToggleCollapse()" title="Collapse pane"><img src="img/collapse.gif" /></td>
      <td>
		<iframe height="800" width="100%" id="main-right-box" frameborder="0"></iframe>
	  </td>
    </tr>
  </table>
</div>
</body>
</html>